﻿using System.Text.Json;
using Worldme.YHChatSDK.Common.Constant;
using Worldme.YHChatSDK.Framework.Utils;
using Worldme.YHChatSDK.Framework.Vo.V1.Req;
using Worldme.YHChatSDK.Framework.Vo.V1.Ret;

namespace YHChatSDKDemo.Services
{
    public class ApiService
    {

        /// <summary>
        /// 发送消息示例
        /// </summary>
        public static void sendMsgDemo()
        {
            ApiSendMsgReqV1 reqV1 = new ApiSendMsgReqV1()
                    .Text(RecvTypeConstant.USER, "8219986", "你好")
                    .AddButton("跳转", ButtonActionTypeConstant.JUMP_URL, "https://www.baidu.com/", null)
                    .AddButton("复制", ButtonActionTypeConstant.COPY, null, "复制成功啦")
                    .AddButton("上报", ButtonActionTypeConstant.REPORT, null, "上报成功啦");
            ApiSendMsgRetV1 apiSendRetV1 = ApiUtil.SendMsg(reqV1);
        }


        /// <summary>
        /// 批量发送消息示例
        /// </summary>
        public static void sendMsgBatchDemo()
        {
            ApiSendMsgBatchReqV1 reqBatchV1 = new ApiSendMsgBatchReqV1()
                    .Text(RecvTypeConstant.GROUP, new List<string> { "552846090", "123456789" }, "你好2")
                    .AddButton("跳转", ButtonActionTypeConstant.JUMP_URL, "https://www.baidu.com/", null)
                    .AddButton("复制", ButtonActionTypeConstant.COPY, null, "复制成功啦")
                    .AddButton("上报", ButtonActionTypeConstant.REPORT, null, "上报成功啦");
            ApiSendMsgBatchRetV1 apiSendMsgBatchRetV1 = ApiUtil.SendMsgBatch(reqBatchV1);
        }

        /// <summary>
        /// 发送消息后再编辑消息示例
        /// 使用场景：点击按钮上报后，再进行动态修改
        /// </summary>
        public static void sendMsgAndEditMsgDemo()
        {
            //发送消息
            ApiSendMsgReqV1 reqV1 = new ApiSendMsgReqV1()
                    .Text(RecvTypeConstant.USER, "8219986", "你好")
                    .AddButton("跳转", ButtonActionTypeConstant.JUMP_URL, "https://www.baidu.com/", null)
                    .AddButton("复制", ButtonActionTypeConstant.COPY, null, "复制成功啦")
                    .AddButton("上报", ButtonActionTypeConstant.REPORT, null, "上报成功啦");
            ApiSendMsgRetV1 apiSendRetV1 = ApiUtil.SendMsg(reqV1);
            String msgId = apiSendRetV1.data.messageInfo.msgId;

            Thread.Sleep(3000);

            //编辑消息
            ApiEditMsgReqV1 editV1 = new ApiEditMsgReqV1()
                    .SetMsgId(msgId)
                    .Text(RecvTypeConstant.USER, "8219986", "哈哈哈哈哈哈")
                    .AddButton("速速跳转", ButtonActionTypeConstant.JUMP_URL, "https://www.baidu.com/", null);
            ApiEditMsgRetV1 apiEditMsgRetV1 = ApiUtil.EditMsg(editV1);
        }


        /// <summary>
        /// 发送消息后再撤回消息示例
        /// </summary>
        public static void sendMsgAndRecllMsgDemo()
        {
            //发送消息
            ApiSendMsgReqV1 reqV1 = new ApiSendMsgReqV1()
                    .Text(RecvTypeConstant.USER, "8219986", "你好")
                    .AddButton("跳转", ButtonActionTypeConstant.JUMP_URL, "https://www.baidu.com/", null)
                    .AddButton("复制", ButtonActionTypeConstant.COPY, null, "复制成功啦")
                    .AddButton("上报", ButtonActionTypeConstant.REPORT, null, "上报成功啦");
            ApiSendMsgRetV1 apiSendRetV1 = ApiUtil.SendMsg(reqV1);
            String msgId = apiSendRetV1.data.messageInfo.msgId;

            Thread.Sleep(3000);

            //撤回消息
            ApiRecallMsgReqV1 editV1 = new ApiRecallMsgReqV1(msgId, RecvTypeConstant.USER, "8219986");
            ApiRecallMsgRetV1 apiRecallMsgRetV1 = ApiUtil.RecallMsg(editV1);
            Console.WriteLine(JsonSerializer.Serialize(apiRecallMsgRetV1));
        }


        /// <summary>
        /// 设置看板示例
        /// </summary>
        public static void setBoardDemo()
        {
            ApiSetBoardReqV1 boardReqV1 = new ApiSetBoardReqV1();
            //对单个用户设置看板
            boardReqV1.Text(RecvTypeConstant.USER, "8219986", "你好");
            //对全局用户设置看板
            //        boardReqV1.Html(null, null, "<h1>我是全局看板，你好朋友</h1>");
            ApiSetBoardRetV1 apiSetBoardRetV1 = ApiUtil.SetBoard(boardReqV1);
        }


        /// <summary>
        /// 取消设置看板示例
        /// </summary>
        public static void disBoardDemo()
        {
            ApiDisBoardReqV1 boardReqV1 = new ApiDisBoardReqV1();
            //取消对单个用户设置的看板
            boardReqV1.Dismiss(RecvTypeConstant.USER, "8219986");
            //取消对全局用户设置的看板
            //        boardReqV1.Dis(null, null);
            ApiDisBoardRetV1 apiDisBoardRetV1 = ApiUtil.DisBoard(boardReqV1);
        }
    }
}
